@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

:: 定义颜色
set "GREEN=[92m"
set "YELLOW=[93m"
set "RED=[91m"
set "NC=[0m"

:: 定义项目根目录和部署目录
pushd %~dp0
cd ..\..\
set "PROJECT_ROOT=%cd%"
set "DEPLOY_DIR=%PROJECT_ROOT%\deploy"

echo %YELLOW%=== 启动 WVP-GB28181-Pro 服务 ===%NC%

:: 检查部署目录是否存在
if not exist "%DEPLOY_DIR%" (
    echo %RED%错误: 部署目录不存在，请先运行 build.bat 脚本构建项目。%NC%
    exit /b 1
)

:: 检查JAR文件是否存在
set "JAR_FILE=%DEPLOY_DIR%\wvp-gb28181-pro.jar"
if not exist "%JAR_FILE%" (
    echo %RED%错误: JAR文件不存在，请先运行 build.bat 脚本构建项目。%NC%
    exit /b 1
)

:: 检查Java是否已安装
where java >nul 2>nul
if %ERRORLEVEL% neq 0 (
    echo %RED%错误: 未找到Java。请先安装Java再运行此脚本。%NC%
    exit /b 1
)

:: 显示Java版本
echo %YELLOW%Java版本:%NC%
java -version

:: 设置JVM参数
set "JAVA_OPTS=-Xms256m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%DEPLOY_DIR%\heapdump\"

:: 创建heapdump目录
if not exist "%DEPLOY_DIR%\heapdump" mkdir "%DEPLOY_DIR%\heapdump"

:: 启动应用
echo %YELLOW%正在启动应用...%NC%
echo %YELLOW%使用JVM参数: %JAVA_OPTS%%NC%
echo %YELLOW%如需停止应用，请按 Ctrl+C%NC%

cd "%DEPLOY_DIR%"
java %JAVA_OPTS% -jar wvp-gb28181-pro.jar

popd
endlocal 